<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>表单列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <!-- <div class="layui-card-header"><i class="fa fa-list"></i> 表单列表</div> -->
          <div class="layui-card-body" pad15>
						<!-- <div class="layui-col-md4" style="padding-bottom:10px">
							<a class="layui-btn layuiadmin-btn-list" href="formadd.php">添加</a>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="datadel(0)">删除</button>
						</div> -->
						<div class="layui-form layui-col-md12" style="padding-bottom:10px">
							{if input('param.hidebid')==1}
							{else}
								{if $blist}
								<div class="layui-inline">
									<label class="layui-form-label" style="width:30px">商户</label>
									<div class="layui-input-block" style="width:120px;margin-left:60px;text-align:left">
										<select name="bid">
											<option value="">自营</option>
											{foreach $blist as $b}<option value="{$b['id']}">{$b['name']}</option>{/foreach}
										</select>
									</div>
								</div>
								{/if}
							{/if}
							<div class="layui-inline layuiadmin-input-useradmin">
								<label class="layui-form-label" style="width:60px">表单名称</label>
								<div class="layui-input-block" style="width:120px;margin-left:90px">
									<input type="text" name="name" autocomplete="off" class="layui-input" value="">
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
							<div class="layui-inline">
								提示：请在左侧菜单中找到[扩展]-[自定义表单] 进行创建表单
							</div>

						</div>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
	layui.laydate.render({ 
		elem: '#ctime',
		trigger: 'click',
		range: '~' //或 range: '~' 来自定义分割字符
	});
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{:url('index')}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
			{type:"checkbox"},
      //{field: 'id', title: 'ID',  width:80},
      {field: 'name', title: '名称'},
      {field: 'ctime', title: '有效时间',templet: '<div>{{d.starttime}} ~ {{d.endtime}}</div>'},
      {field: 'createtime', title: '创建时间',templet:function(d){ return date('Y-m-d H:i',d.createtime)},width:150},
      {field: 'status', title: '状态',width:100},
      {field: 'operation', title: '操作',templet: '<div><button class="table-btn" onclick="chooseform(\'{{d.id}}\')">选择</button></div>',align:'center'}
    ]]
  });
	function chooseform(id){
		var index = layer.load();
		$.post('',{id:id},function(res){
			layer.close(index);
			window.parent.chooseform(res.data,"{$Request.param.args}");
			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			parent.layer.close(index); //再执行关闭
		});
	}
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	</script>
</body>
</html>